<?php
/*
 * Created on 2012-11-22
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
function isHaveAuth($menus,$to,$authStr)
{
	//echo $authStr;
	if(strpos($to,"ajax")!==false)
	{
		$to = substr($to,0,strpos($to,"&"));
	}
	//echo $to;exit;
	$arrAuth = explode(",",$authStr);
	$isHaveAuth = false;
	$to = explode("&",$to);
	$newTo[] = $to[0];
	$newTo[] = $to[1];
	$to = implode("&",$newTo);
	foreach($menus as $v)
	{
		if(strpos($to,$v['link'])!==false)
		{
			if(in_array($v['id'],$arrAuth))
			{
				//echo "1111";
				$isHaveAuth = true;
				break;
			}
		}
        foreach($v['menus'] as $v2)
		{
			if(strpos($to,$v2['link'])!==false)
			{
				if(in_array($v2['id'],$arrAuth))
				{
					
					$isHaveAuth = true;
					break;
				}
			}
		}
	}
	return $isHaveAuth;
}
$DB->db_query("SELECT * FROM admin_menu order by parent,rank");
$menus = array();
$findMenus = array();
while($r= $DB->db_fetch_row())
{
	$menus[] = $r;
}
$findMenus = $menus;
$arrAuth = explode(",",$_SESSION['adminUser']['auth']);

foreach($menus as $m1)
{
	if($m1['parent']==0 && $m1['isShow']==1)
	{
		$subMenus = array();
		$isHaveAuth = false;
		foreach($findMenus as $m2)
		{
			if($m2['parent']==$m1['id'] && $m2['isShow']==1)
			{
				if(in_array($m2['id'],$arrAuth))
			    {
				    $subMenus[] = array("id"=>$m2['id'],"link"=>$m2['link'],"name"=>$m2['name']);
				    $isHaveAuth = true;
			    }
			}
		}
		if(in_array($subMenus['id'],$arrAuth) || $isHaveAuth)
		{
			$CONF['menus'][] = array("id"=>$m1['id'],"name"=>$m1['name'],"link"=>$m1['link'],"menus"=>$subMenus);
		}
	}
}
unset($findMenus);
unset($menus);
//$CONF['menus'][] = array("id"=>"1_0","name"=>"用户注册指标","menus"=>array(
//                                                              array("id"=>"1_1","link"=>"pfClick","name"=>"平台点击量"),
//                                                              array("id"=>"1_2","link"=>"pfReg","name"=>"平台注册量"),
//                                                              array("id"=>"1_3","link"=>"myReg","name"=>"验证注册量")
//                                                              ));
//$CONF['menus'][] = array("id"=>"2_0","name"=>"注册用户管理","menus"=>array(array("id"=>"2_1","link"=>"members","name"=>"会员管理")));
//$CONF['menus'][] = array("id"=>"3_0","name"=>"游戏信息管理","menus"=>array(array("id"=>"3_1","link"=>"members","name"=>"游戏管理")));
//$CONF['menus'][] = array("id"=>"4_0","name"=>"后台用户管理","menus"=>array(
//                                                              array("id"=>"4_1","link"=>"admin&op=shwModPass","name"=>"修改密码"),
//                                                              array("id"=>"4_2","link"=>"admin&op=shwAdmin","name"=>"用户管理"),
//                                                              array("id"=>"4_3","link"=>"admin&op=shwRole","name"=>"角色管理"),
//                                                              array("id"=>"4_4","link"=>"admin&op=shwAuth","name"=>"权限管理")));
?>
